import com.tushen.UVTask;
import com.tushen.task.Dye3;
import com.tushen.task.NC;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.tushen.utils.Utils;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by likun on 2020/9/10.
 */
public class UVRead {

    @After
    public void aftrer(){

    }
    @Before
    public void befor(){

    }

    @Test
    public void test1(){
        String str=" 1990-01-01 00:00:00";
        Date date=new Date();
        System.out.println(date);
        NC.test();;
    }
    @Test
    public void test3(){
        String regEx="[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher("polcon202004151800.tfi");
        System.out.println( m.replaceAll("").trim());
    }

    @Test
    public void dy3DumpTif(){
//        String dirPath="D:\\dstdye\\2020070100\\dyetif3";
//        String version="20200703";
//        Dye3.dumpTif(dirPath,version);

        UVTask.interpolateToTiff();
    }



    @Test
    public void readUV(){
        System.out.println("test");
        String path="D:\\data\\2020070100\\dye.csv";
        double[][] txtArray = Utils.readTxtToArray(path);
        System.out.println(txtArray.length);
        if(txtArray.length>0){
            System.out.println(txtArray[0].length);
        }
    }
    @Test
    public void test2(){
//        String fileDir="D:\\其他\\hesu\\202004150900扩散96_145";
//        String[] dtms=getMinMaxDtm(fileDir);
//        System.out.println(dtms[0]);
//        System.out.println(dtms[1]);

        String str="202012120100_04.0.tif";
//        String str="202004250000_01.0.tif";
        String dtmStr=str.substring(0,12);
        int elevation=Integer.parseInt(str.substring(13,15));
        System.out.println(dtmStr);
        System.out.println(elevation);
        System.out.println(str.substring(13,15));
    }

    private String[] getMinMaxDtm(String fileDir){
        File file=new File(fileDir);
        String dtmMin="";
        String dtmMax="";
        Date dtmMi=null;
        Date dtmMa=null;
        if(file.isDirectory()){
            File[] files=file.listFiles();
            for (int i=0;i<files.length;i++){
                if(files[i].getName().endsWith("dat")) {
                    String regEx="[^0-9]";
                    Pattern p = Pattern.compile(regEx);
                    Matcher m = p.matcher(files[i].getName());
                    String dtmStr=m.replaceAll("").trim();
                    SimpleDateFormat smt=new SimpleDateFormat("yyyyMMddHHmm");
                    try {
                        Date dtm= smt.parse(dtmStr);
                        if(dtmMi==null||dtmMi.getTime()>dtm.getTime()){
                            dtmMi=dtm;
                            dtmMin=dtmStr;
                        }
                        if(dtmMa==null||dtmMa.getTime()<dtm.getTime()){
                            dtmMa=dtm;
                            dtmMax=dtmStr;
                        }

                    }catch (Exception e){
                        e.printStackTrace();
                    }

                }
            }
        }
        return new String[]{dtmMin,dtmMax};
    }



}
